package net.jbot.loader;

import java.applet.Applet;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;

@SuppressWarnings("serial")
public class BotApplet extends Applet {
	
	private Applet loader;
	
    public ClassLoader getClasses(String url) throws MalformedURLException {
        return new URLClassLoader(new URL[] { new URL(url) });
}
	
	public Applet loadStub() throws Exception {
		System.out.println("Loading stub.");
		BotStub stub = new BotStub();
		System.out.println("Loading client class.");
		Class<?> mainClass = getClasses(stub.getCodeBase() + stub.gp).loadClass("client");
		System.out.println("Starting applet.");
		loader = (Applet) mainClass.newInstance();
		System.out.println("Setting stub.");
		loader.setStub(stub);
		loader.init();
		loader.start();
		return loader;
	}

}
